/**
 * @param {number[]} tasks
 * @param {number} sessionTime
 * @return {number}
 */
 var minSessions = function(tasks, sessionTime) {
  tasks.sort((a,b) => a-b)
  const template = tasks.slice()
  const n = tasks.length
  let ans = Number.MAX_SAFE_INTEGER
  const dfs = (sum, idx, cnt) => {
    if(tasks.every(item => item === 0)){
      ans = Math.min(ans, cnt)
      tasks = template
      cnt = 0
      return
    }
    if(sum + tasks[idx] >= sessionTime){
      sum = 0
      cnt++
    }
    for(let i = idx; i<n; i++){
      const temp = tasks[i]
      sum += tasks[i]
      tasks[i] = 0
      dfs(sum, i+1, cnt)
      sum -= tasks[i]
      tasks[i] = temp
    }
  }
  dfs(0, 0, 0)
  return ans
};